import { Component, Input, OnChanges, OnInit, SimpleChanges } from '@angular/core';

import { HttpMockService, User } from '@core/base';

@Component({
  selector: 'app-modal-user-description',
  templateUrl: './modal-user-description.component.html'
})
export class ModalUserDescriptionComponent implements OnChanges {
  @Input()
  userid!: string;

  user!: User;
  isLoading = false;

  constructor(private httpMockSrc: HttpMockService) {}

  ngOnChanges(changes: SimpleChanges): void {
    if (changes['userid']) {
      this.loadUser();
    }
  }

  loadUser(): void {
    this.isLoading = true;
    this.httpMockSrc.getUser(this.userid).subscribe(data => {
      this.user = data;
      this.isLoading = false;
    });
  }
}
